package com.example.airobotsettings.dao;

import com.example.airobotsettings.entity.BackgroundUser;
import lombok.Data;

import java.util.HashMap;
import java.util.Map;

@Data
public class Result<T> {

    private int code;
    private String message;
    private T data;

    public static <T> Result<T> success(T data) {
        Result<T> result = new Result<>();
        result.setCode(200);
        result.setMessage("success");
        result.setData(data);
        return result;
    }

    public static <T> Result<T> error(int code, String message) {
        Result<T> result = new Result<>();
        result.setCode(code);
        result.setMessage(message);
        return result;
    }

    public static Result<Map<String,Object>> loginSuccess(BackgroundUser user, String token){
        HashMap<String, Object> data = new HashMap<>();
        data.put("user",user);
        data.put("token",token);
        return success(data);
    }


}
